package com.huilian.iotbox.admin.controller;

import com.huilian.iotbox.admin.service.CustomerInfoService;
import com.huilian.iotbox.admin.service.CustomerServiceInfoService;
import com.huilian.iotbox.admin.service.UserService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.controller.BaseController;
import com.huilian.iotbox.data.dto.CustomerInfoDto;
import com.huilian.iotbox.data.dto.CustomerServiceInfoDto;
import com.huilian.iotbox.data.enums.RoleEnum;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author LinYinDong
 * @date 2023/12/6 10:07
 */
@RestController
@RequestMapping("/api/customerServiceInfo")
public class CustomerServiceInfoController extends BaseController {
    @Autowired
    private CustomerServiceInfoService customerServiceInfoService;
    @Autowired
    private UserService userService;
    @PostMapping("/findCustomerServiceInfoByStoreId")
    public ServerResponse findCustomerServiceInfoByStoreId(@RequestBody CustomerServiceInfoDto customerServiceInfoDto, HttpServletRequest request){
        UserInfo userInfo = userService.getLoginUserInfo(request);
        customerServiceInfoDto.setUserInfo(userInfo);
        return ServerResponse.createBySuccess(customerServiceInfoService.findCustomerServiceInfoByStoreId(customerServiceInfoDto));
    }
    @PostMapping("/editCustomerServiceInfo")
    public ServerResponse editCustomerServiceInfo(@RequestBody CustomerServiceInfoDto customerServiceInfoDto, HttpServletRequest request){
        UserInfo userInfo = userService.getLoginUserInfo(request);
        if (!RoleEnum.SUPER_ADMINISTRATOR.getRoleId().equals(userInfo.getRoleId())) {
            return ServerResponse.createByErrorMessage("您没有权限处理，请联系管理员开通权限");
        }
        customerServiceInfoDto.setUserInfo(userInfo);
        return customerServiceInfoService.editCustomerServiceInfo(customerServiceInfoDto);
    }
}
